﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.TextEditor.Document;
using System.IO;
using System.Windows.Forms;
using System.Drawing;

namespace MetaNote.Controls
{
    public class NiceTextBox : ICSharpCode.TextEditor.TextEditorControl
    {
        public NiceTextBox() 
        {
            
        }
        public string SelectedText
        {
            get
            {
                return this.ActiveTextAreaControl.SelectionManager.SelectedText;
            }
            set
            {
                if (this.ActiveTextAreaControl.SelectionManager.HasSomethingSelected)
                {
                    ISelection s = this.ActiveTextAreaControl.SelectionManager.SelectionCollection[0];
                    this.Document.Replace(s.Offset, s.Length, value);
                    this.Refresh();
                }
            }
        }

        public void SetMainCodeLanguage(string languageName)
        {
            string dir = Path.GetDirectoryName(GetType().Assembly.Location);
            FileSyntaxModeProvider fsmProvider = new FileSyntaxModeProvider(dir);
            HighlightingManager.Manager.AddSyntaxModeFileProvider(fsmProvider); // Attach to the text editor.
            this.SetHighlighting(languageName);
        }

        public void Cut()
        {
            this.ActiveTextAreaControl.TextArea.ClipboardHandler.Cut(null, null); 
        }

        public void Copy()
        {
            this.ActiveTextAreaControl.TextArea.ClipboardHandler.Copy(null, null);
        }

        public void Paste()
        {
            this.ActiveTextAreaControl.TextArea.ClipboardHandler.Paste(null, null);
        }

        public void SelectAll()
        {
            this.ActiveTextAreaControl.TextArea.ClipboardHandler.SelectAll(null, null);
        }

        public void Delete()
        {
            this.ActiveTextAreaControl.TextArea.ClipboardHandler.Delete(null, null);
        }
    }
}
